import { app1 as request } from '@/api/request';

/**
 * @description 获取基址
 * @method Post
 */
export function getBaseUrl<R, T>() {
  return request.Post<R, T>('/chat/baseUrl');
}

/**
 * @description 开启会话
 * @method Post
 */
export function startConversation<R, T>() {
  return request.Post<R, T>('/chat/startConversation');
}

/**
 * @description 文本转语音
 * @method Post
 */
export function textQuery<R, T>(data: any) {
  return request.Post<R, T>('/chat/textQuery', {
    headers: {
      'Content-Type': 'application/json',
    },
    openWhenHidden: true,
    body: JSON.stringify(data),
  });
}

/**
 * @description textQueryFlux
 * @method Post
 */
export function textQueryFlux<R, T>(conversationId: number, text: string) {
  return request.Post<R, T>('/chat/textQueryFlux', JSON.stringify({ conversationId, text }), {
    headers: {
      'Content-Type': 'application/json',
    },
  });
}

/**
 * @description 语音文件转文本
 * @method Post
 */
export function speechToText<R, T>(file: any) {
  return request.Post<R, T>('/chat/speechToText', file, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
}

/**
 * @description 语音文件转换为文本，然后将回答转换为语音
 * @method Post
 */
export function speechQuery<R, T>(conversationId: number, file: any) {
  return request.Post<R, T>('/chat/speechQuery', {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    params: {
      conversationId,
      file,
    },
  });
}

/**
 * @description 获取会话地址
 * @method Post
 */
export function baseUrl<R, T>() {
  return request.Post<R, T>('/chat/baseUrl', {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
  });
}

/**
 * @description 文件下载请求
 * @method Get
 */
export function speechDownload<R, T>(taskId: number) {
  return request.Get<R, T>('/chat/speechDownload', {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    responseType: 'blob',
    params: {
      taskId,
    },
  });
}
